package com.energyfuture.system.api.factory;

import java.util.List;

import com.energyfuture.system.api.domain.SysCompany;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import com.energyfuture.common.core.domain.R;
import com.energyfuture.system.api.RemoteUserService;
import com.energyfuture.system.api.domain.SysUser;
import com.energyfuture.system.api.model.LoginUser;
import com.energyfuture.system.api.model.SegmentEntity;
import com.energyfuture.system.api.model.SysparaEntity;

/**
 * 用户服务降级处理
 * 
 * @author energyfuture
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysparaEntity> querySysParam()
            {
                return R.fail("获取系统参数失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SegmentEntity>> selectSysIPs()
            {
                return R.fail("获取系统ips失败:" + throwable.getMessage());
            }

            @Override
            public R<Integer> updateUser(SysUser user)
            {
                return R.fail("修改失败:" + throwable.getMessage());
            }

            @Override
			public R<SysUser> selectUserById(String userId) {
				return R.fail("获取用户信息失败:" + throwable.getMessage());
			}

            @Override
            public R<SysUser> selectUserByPhone(String phone) {
                return R.fail("获取用户信息失败:" + throwable.getMessage());
            }

			@Override
			public R<List<String>> selectUserNameByPostCodeAndDeptId(String postCode, String deptId) {
				return R.fail("根据部门id查询用户名称失败:" + throwable.getMessage());
			}

			//添加
            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser) {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysCompany> getCompanyInfo(String getCompanyID) {
                return R.fail("企业邀请码不正确:" + throwable.getMessage());
            }

        };
    }
}
